#!/usr/local/BLBIN/bin/php
<?php
function install_software()
{
	global $plast_bin;
	global $api_license;
	echo "\x1b" . '[32m Installation will take about 10 minutes  ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	echo "\x1b" . '[32m Please Wait... ' . "\x1b" . '[0m ' . "\n";
	echo 'Installing Linux Malware Detect..';
	system(' wget http://rep0.admin-ahead.com/sources/cpanel-plugins/lmd-manager/lmd-manager-installer-v3.0.0.sh');
	system('chmod +x lmd-manager-installer-v3.0.0.sh');
	system('./lmd-manager-installer-v3.0.0.sh 1 ');
	echo "\n\n" . ' ' . "\x1b" . '[32m  Linux Malware Detect has been installed.' . "\x1b" . '[0m ' . "\n\n";
	exit();
}

function exec_output($cmd)
{
	exec($cmd, $output, $return_var);
	return $output[0];
}

function get_http_response_code($domain1)
{
	$ch = curl_init($domain1);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$output = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return $httpcode;
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'lmd';
$api = 'https://api.begpl.com/api/getinfo?key=' . $key;
$api_license = 'https://api.begpl.com/api/license?key=' . $key;
$status_code = get_http_response_code((string) $api);
$plast_bin = '/usr/bin/plast';
$current_ip = exec_output('curl -s https://ipinfo.io/ip');
$domain_show = 'begpl.com';
$brand_show = 'Licenses4Host';
$hostname_show = exec_output('hostname');
$server_type = 'Linux Malware Detect';
$status = false;
$server_range = 0;
$firewall_stop = false;
$firewall_stop_1 = false;
$force = false;
$action = (1 < count($argv) ? $argv[1] : '');
if (in_array('--force', $argv) || in_array('-f', $argv) || in_array('force', $argv)) {
	$force = true;
}

echo "\n";
echo "\x1b" . '[32mPlease Wait important packages need to be installed ... ' . "\x1b" . '[0m ' . "\n";

if ($action != 'install') {
	if (!file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd') || !file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd')) {
		echo "\x1b" . '[31mCMalware Detect is not detected ' . "\x1b" . '[0m ' . "\n";
		echo "\x1b" . '[31mYou need to install Malware Detect ' . "\x1b" . '[0m ' . "\n";
		echo "\n";
		echo "\n";
		echo "\x1b" . '[32mFor quick installation ' . "\x1b" . '[0m ' . "\n";
		echo "\x1b" . '[32m/usr/bin/installer_run install  ' . "\x1b" . '[0m ' . "\n";
		echo "\n";
		exit();
		exit();
	}
	else {
		$installed = true;
	}
}

if (!file_exists('/etc/redhat-release')) {
	system('yum install deltarpm  -y  1> /dev/null');
}

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

$output = exec_output('curl -s   \'' . $api . '\' ');

if ($status_code != '200') {
	exec('rm -rf /usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd/license.php  > /dev/null 2>&1');
	printf("\x1b" . '[31m Something Went Wrong [Unknown Ip]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];

if ((string) $get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ((string) $get_brand_show != '') {
	$brand_show = $get_brand_show;
}

echo "\n\n";
printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Thank you for using our Malware Detect Licensing System  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36mCopyright © 2019-2021 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");
echo "\n";
exec('killall -g yum > /dev/null 2>&1');
system('rm -rf  /usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd/license.php  &> /dev/null');
system('wget http://api.begpl.com/api/files/' . $key . '/license.php?key=' . $key . '  -O /usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd/license.php &> /dev/null');

if ($action == 'install') {
	if (!file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd')) {
		install_software();
		echo "\n";
		echo "\n";

		if (!file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/aast-lmd')) {
			printf("\x1b" . '[31mInstallation Status FAILED ' . "\x1b" . '[0m ' . "\n");
			$installed = false;
			$status = false;
		}
		else {
			printf("\x1b" . '[32mInstallation Status OK ' . "\x1b" . '[0m ' . "\n");
			$installed = true;
			$status = true;
		}
	}

	echo "\n";
	echo "\n";
}

if (preg_match('/Has valid licence ............ SUCCESS./', $output_check_license)) {
	echo 'Malware Detect License Activated!';
	echo "\n";
}
else {
	echo 'Malware Detect License Activated!';
	echo "\n";
}

?>